#define _CRT_SECURE_NO_WARNINGS 1
//#include <iostream>
//using namespace std;
//
//int main()
//{
//    int x;
//    cin >> x;
//
//    int res = 0;
//    while (x)
//    {
//        if (x % 2 == 1)
//            res++;
//        x /= 2;
//    }
//
//    cout << res << endl;
//
//    return 0;
//}
#include<iostream>
#include<cmath>
using namespace std;
bool canBalance(int m, int weights[], int n) {
    if (m == 0) {
        return true;
    }
    if (n == 0) {
        return false;
    }
    // Try placing the current weight on the left side
    if (canBalance(m - weights[n - 1], weights, n - 1)) {
        return true;
    }
    // Try placing the current weight on the right side
    if (canBalance(m + weights[n - 1], weights, n - 1)) {
        return true;
    }
    // Try not using the current weight
    return canBalance(m, weights, n - 1);
}

int main()
{
    int n, m;
    int weight[101];
    cin >> n >> m;
    for (int i = 0; i <= 100; i++)
    {
        weight[i] = pow(n, i);
    }
    if (canBalance(m, weight, 101)) {
        cout << "YES";
    }
    else
        cout << "NO";
	return 0;
}


